package com.netty.demo.server.netty.listener;

import com.netty.demo.server.dto.UdpRequestMessage;
import com.netty.demo.server.netty.enums.RequestHeaderProtocol;
import com.netty.demo.server.netty.processor.ProtocolProcessor;
import com.netty.demo.server.netty.processor.ProtocolProcessorFactory;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author Administrator 余秀良
 * @version 1.0
 * <p>date: 2019年09月25日  10:46 </p>
 * <p>address: 四川成都 </p>
 */
@Component
public class UdpHandlerServiceListener {
    @Async
    @EventListener
    public void execute(UdpRequestMessage message) {
        RequestHeaderProtocol protocol = RequestHeaderProtocol.value(message.getHead());
        if (protocol != null) {
            ProtocolProcessor service = ProtocolProcessorFactory.getProtocolProcessor(protocol);
            if (service != null) {
                service.execute(message);
            }
        }
    }
}
